package org.dromara.admin.ocr.controller;

import com.fasterxml.jackson.databind.JsonNode;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.dromara.admin.ocr.service.OcrService;
import org.dromara.common.core.domain.R;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.common.web.core.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * OCR识别
 *
 * @author Lion Li
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/ocr")
public class OcrController extends BaseController {

    @Autowired
    private OcrService ocrService;

    /**
     * 房产信息识别
     */
    @PostMapping("/estate")
    public R<JsonNode> estateOcr(@RequestBody Map<String, String> req) {
        return R.ok(ocrService.estateOcr(req.get("url")));
    }

    /**
     * 身份证识别
     */
    @PostMapping("/idCard")
    public R<JsonNode> idcardOcr(@RequestBody Map<String, String> req) {
        return R.ok(ocrService.idCardOcr(req.get("imageId")));
    }

    /** 个人三要素对比 */
    @PostMapping("/personal3")
    public R<JsonNode> personal3(@RequestBody Map<String, Object> req) {
        req.put("user_id", LoginHelper.getUserId());
        return R.ok(ocrService.personal3(req));
    }

    @Data
    public static class EstateRequest {
        private String url;
    }

    @Data
    public static class IdCardRequest {
        private String imageId;
    }
}
